package com.wlc.controller;

import com.wlc.pojo.Result;
import com.wlc.service.DeptStatsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/stats/dept")
@Slf4j
public class DeptStatsController {

    @Autowired
    private DeptStatsService deptStatsService;

    /**
     * 获取部门人数统计
     */
    @GetMapping("/employee")
    public Result<List<Map<String, Object>>> getDeptEmployeeStats() {
        log.info("获取部门人数统计");
        try {
            List<Map<String, Object>> stats = deptStatsService.getDeptEmployeeStats();
            return Result.success(stats);
        } catch (Exception e) {
            log.error("获取部门人数统计失败: {}", e.getMessage());
            return Result.error(e.getMessage());
        }
    }

    /**
     * 获取部门性别分布
     */
    @GetMapping("/{deptId}/gender")
    public Result<List<Map<String, Object>>> getDeptGenderStats(@PathVariable Long deptId) {
        log.info("获取部门性别分布: deptId={}", deptId);
        try {
            List<Map<String, Object>> stats = deptStatsService.getDeptGenderStats(deptId);
            return Result.success(stats);
        } catch (Exception e) {
            log.error("获取部门性别分布失败: {}", e.getMessage());
            return Result.error(e.getMessage());
        }
    }
}